//
//  ViewController.m
//  YXLAlertView
//
//  Created by yanxinlong on 16/1/13.
//  Copyright © 2016年 yanxinlong. All rights reserved.
//

#import "ViewController.h"
#import "ShowAlertView.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self creatUI];
}

- (void)creatUI {
     //只输出一句提示
    UIButton *warning = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 80, 40)];
    [warning setTitle:@"警告" forState:UIControlStateNormal];
    warning.backgroundColor = [UIColor redColor];
    [warning addTarget:self action:@selector(warningClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:warning];
    
    //输出提示确定和取消
    UIButton *selectButton = [[UIButton alloc]initWithFrame:CGRectMake(100, 150, 80, 40)];
    selectButton.backgroundColor = [UIColor greenColor];
    [selectButton setTitle:@"确定吗" forState:UIControlStateNormal];
    [selectButton addTarget:self action:@selector(selectButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:selectButton];
    
    //让用户输入内容 确定 取消
    UIButton *returnButton = [[UIButton alloc]initWithFrame:CGRectMake(100, 200, 80, 40)];
    returnButton.backgroundColor = [UIColor blackColor];
    [returnButton setTitle:@"退款" forState:UIControlStateNormal];
    [returnButton addTarget:self action:@selector(returnButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:returnButton];

}

- (void)warningClick {
    ShowAlertView *alert = [[ShowAlertView alloc]initWithAlertString:@"这是一个警告!"];
    [self.view addSubview:alert];

}

- (void)selectButtonClick {
    ShowAlertView *alert = [[ShowAlertView alloc]initWithTitle:@"选择是否确定" andMessage:@"你确定你不傻吗?"];
    alert.sureBlock = ^{
        [self sureButtonClickEvent];
    };
    [self.view addSubview:alert];
}

- (void)returnButtonClick {
    ShowAlertView *alert = [[ShowAlertView alloc]initWithTitle:@"退款原因" andContentPlaceholder:@"请输入退款原因"];
    alert.sendBlock = ^(NSString *text){
        [self sendMessageWhenSureButtonClickEvent:text];
    };
    [self.view addSubview:alert];

}

- (void)sureButtonClickEvent {
    NSLog(@" 你点击了确定");
}

- (void)sendMessageWhenSureButtonClickEvent:(NSString *)message {
    if ([message length] > 0) {
        NSLog(@"%@",message);
    }else {
        NSLog(@" 请重新输入");
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
